package fr.enseirb.mycub.structures;

import java.util.ArrayList;

import android.database.Cursor;
import android.provider.BaseColumns;

import com.google.android.maps.GeoPoint;

import fr.enseirb.mycub.db.ParkingDBConstants;

public class Parking extends Station {
	private String mAddress;
	private int parkingPlaces;

	public static final String ADDRESS = "address";
	public static final String PARKING_PLACES = "parkingPlaces";

	public Parking() {
		super();
	}

	public void setAddress(String address) {
		mAddress = address;
	}

	public String getAddress() {
		return mAddress;
	}

	public int getParkingPlaces() {
		return parkingPlaces;
	}

	public void setParkingPlaces(int parkingPlaces) {
		this.parkingPlaces = parkingPlaces;
	}

	public static ArrayList<Parking> getParkingsFromCursor(Cursor cursor){

		ArrayList<Parking> items = new ArrayList<Parking>();

		if(cursor.getCount() == 0 ) return items;

		//------- parking table -------

		int latitudeColumn = cursor
				.getColumnIndex(ParkingDBConstants.KEY_LATITUDE);
		int longitudeColumn = cursor
				.getColumnIndex(ParkingDBConstants.KEY_LONGITUDE);
		int placesColumn = cursor
				.getColumnIndex(ParkingDBConstants.KEY_PLACES);
		int idColumn = cursor
				.getColumnIndex(BaseColumns._ID);

		cursor.moveToFirst();
		Parking l = null;

		int size = cursor.getCount();
		for(int i =  0; i < size; i ++){
			l = new Parking();
			l.mId = cursor.getInt(idColumn);
			int lat = cursor.getInt(latitudeColumn);
			int lon = cursor.getInt(longitudeColumn);
			l.mGeoPoint = new GeoPoint(lat,lon);
			l.parkingPlaces = cursor.getInt(placesColumn);
			items.add(l);
			cursor.moveToNext();
		}

		cursor.close();

		return items;
	}
}